import axios from "axios";
// import { getUsername, getUid } from "@/router/user";

// axios.defaults.withCredentials = true;
const Axios = axios.create({
  baseURL: "",
  timeout: 5000,
  withCredentials: true,
});
// 添加请求拦截器
// axios.interceptors.request.use(
//   (config) => {
//     // 在发送请求之前做些什么
//     let uid = getUid();
//     let user = getUsername();
//     config.headers["Cookie"] = `uid=${uid}; user=${user}`;
//     return config;
//   },
//   (error) => {
//     // 对请求错误做些什么
//     return Promise.reject(error);
//   }
// );
Axios.interceptors.response.use(
  (response) => {
    // console.log(response);
    return response.data;
  },
  (error) => {
    console.log(error);
    if (error.response && error.response.data && error.response.data.Msg) {
      return Promise.reject(error.response.data.Msg);
    }
    return Promise.reject(error.message);
  }
);

export { Axios };
